{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# 一、Pandas 数据类型\n",
    "> 基于numpy封装的，用于处理表格和混杂数据的库\n",
    "> 1. 标签化数据结构\n",
    "> 2. 灵活处理缺失数据\n",
    "> 3. 智能数据对齐\n",
    "> 4. 强大的IO工具\n",
    "> 5. 时间处理\n",
    "\n",
    "所以，numpy中方法同样适用于pandas 。"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "4dd98fef5ca76034"
  },
  {
   "cell_type": "markdown",
   "source": [
    "## series 数据结构"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "a89aaa97dea6a79b"
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "# series 创建\n",
    "import pandas as pd\n",
    "import numpy as np"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T05:53:35.739658500Z",
     "start_time": "2025-08-26T05:53:35.312926Z"
    }
   },
   "id": "526b0897d32f5457"
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "设置索引:\n",
      " a    1.0\n",
      "1    3.0\n",
      "c    5.0\n",
      "D    6.0\n",
      "e    8.0\n",
      "Name: series, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "s = pd.Series([1, 3, 5, np.nan, 6, 8])\n",
    "s = pd.Series([1, 3, 5, 6, 8], index=['a', 1, 'c', 'D', 'e'], dtype=float, name='series')\n",
    "print('设置索引:\\n', s)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:41:41.288686400Z",
     "start_time": "2025-08-26T02:41:41.248966800Z"
    }
   },
   "id": "978ae6281e178979"
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "通过dict创建:\n",
      " a    1\n",
      "b    2\n",
      "c    3\n",
      "d    4\n",
      "e    5\n",
      "f    6\n",
      "dtype: int64\n",
      "取部分数据:\n",
      " b    2\n",
      "c    3\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 通过dict 创建\n",
    "d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6}\n",
    "s = pd.Series(d)\n",
    "print('通过dict创建:\\n', s)\n",
    "s1 = pd.Series(d, index=['b', 'c', ])\n",
    "print('取部分数据:\\n', s1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:57:18.740644300Z",
     "start_time": "2025-08-26T02:57:18.714344600Z"
    }
   },
   "id": "94d5f2954e263613"
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "索引: Index(['a', 'b', 'c', 'd', 'e'], dtype='object')\n",
      "值: [1 2 3 4 5]\n",
      "名称: None\n",
      "数据类型: int64\n",
      "是否为空: a    False\n",
      "b    False\n",
      "c    False\n",
      "d    False\n",
      "e    False\n",
      "dtype: bool\n",
      "长度: 5\n",
      "形状: (5,)\n",
      "维度: 1\n",
      "内存大小: 252\n"
     ]
    }
   ],
   "source": [
    "# 属性\n",
    "print('索引:', s.index)\n",
    "print('值:', s.values)\n",
    "print('名称:', s.name)\n",
    "print('数据类型:', s.dtype)\n",
    "print('是否为空:', s.isnull())\n",
    "\n",
    "print('长度:', s.size)\n",
    "print('形状:', s.shape)\n",
    "print('维度:', s.ndim)\n",
    "print('内存大小:', s.memory_usage())\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:51:58.785824500Z",
     "start_time": "2025-08-26T02:51:58.751938800Z"
    }
   },
   "id": "77be2c46e24ee72b"
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "显式索引： 1\n",
      "隐式索引： 1\n",
      "索引： 1\n",
      "索引： 1\n"
     ]
    }
   ],
   "source": [
    "# 索引\n",
    "print('显式索引：', s.loc['a'])\n",
    "print('隐式索引：', s.iloc[0])\n",
    "print('索引：', s.at['a'])\n",
    "print('索引：', s.iat[0])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:52:01.055403500Z",
     "start_time": "2025-08-26T02:52:01.036124700Z"
    }
   },
   "id": "9ad1411870857588"
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原始数据： a    1\n",
      "b    2\n",
      "c    3\n",
      "d    4\n",
      "e    5\n",
      "dtype: int64\n",
      "数据： 1\n",
      "数据： 1\n",
      "筛选 ： c    3\n",
      "d    4\n",
      "e    5\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 访问数据\n",
    "print('原始数据：', s)\n",
    "# print('数据：',s[0]) # 存在警告信息\n",
    "print('数据：', s['a'])\n",
    "print('数据：', s.iloc[0])\n",
    "print('筛选 ：', s[s > 2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:55:09.216301200Z",
     "start_time": "2025-08-26T02:55:09.189229800Z"
    }
   },
   "id": "757ef39a7973c464"
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取前n个数据 a    1\n",
      "b    2\n",
      "c    3\n",
      "dtype: int64\n",
      "获取后n个数据 d    4\n",
      "e    5\n",
      "f    6\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# 获取前n个数据\n",
    "print('获取前n个数据', s.head(3))\n",
    "print('获取后n个数据', s.tail(3))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T02:57:23.716017400Z",
     "start_time": "2025-08-26T02:57:23.696510900Z"
    }
   },
   "id": "70914d603afe41cf"
  },
  {
   "cell_type": "markdown",
   "source": [
    "## DataFrame 数据结构"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "4b867b4f7b1b0be"
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据类型： <class 'pandas.core.frame.DataFrame'>\n",
      "每一列的数据类型： <class 'pandas.core.series.Series'>\n"
     ]
    }
   ],
   "source": [
    "# 通过series创建\n",
    "s1 = pd.Series([1, 2, 3, 4, 5])\n",
    "s2 = pd.Series([6, 7, 8, 9, 10])\n",
    "df = pd.DataFrame({'第一列': s1, '第二列': s2})\n",
    "\n",
    "print('数据类型：', type(df))\n",
    "print('每一列的数据类型：', type(df['第一列']))  # Series"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:05:51.122010100Z",
     "start_time": "2025-08-26T06:05:51.109093300Z"
    }
   },
   "id": "4d127c850cc994e9"
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "每一列的数据类型： <class 'pandas.core.series.Series'>\n"
     ]
    },
    {
     "data": {
      "text/plain": "   Id Name  Age\n0   1  wdp   18\n1   2  wdm   19\n2   3  wdy   20\n3   4  wdf   21\n4   5  wdq   22",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Id</th>\n      <th>Name</th>\n      <th>Age</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1</td>\n      <td>wdp</td>\n      <td>18</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2</td>\n      <td>wdm</td>\n      <td>19</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>3</td>\n      <td>wdy</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>4</td>\n      <td>wdf</td>\n      <td>21</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>5</td>\n      <td>wdq</td>\n      <td>22</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过字典来创建\n",
    "d = {'Id': [1, 2, 3, 4, 5], 'Name': ['wdp', 'wdm', 'wdy', 'wdf', 'wdq'], 'Age': [18, 19, 20, 21, 22]}\n",
    "df = pd.DataFrame(d)\n",
    "print('每一列的数据类型：', type(df['Id']))  # Series\n",
    "# df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:09:49.606948300Z",
     "start_time": "2025-08-26T06:09:49.598466900Z"
    }
   },
   "id": "5affe097cff9d39b"
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "  Name  Age\n1  wdp   18\n2  wdm   19\n3  wdy   20\n4  wdf   21\n5  wdq   22",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Name</th>\n      <th>Age</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>1</th>\n      <td>wdp</td>\n      <td>18</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>wdm</td>\n      <td>19</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>wdy</td>\n      <td>20</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>wdf</td>\n      <td>21</td>\n    </tr>\n    <tr>\n      <th>5</th>\n      <td>wdq</td>\n      <td>22</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 指定索引和列\n",
    "df = pd.DataFrame(\n",
    "    {\n",
    "        'Name': ['wdp', 'wdm', 'wdy', 'wdf', 'wdq'],\n",
    "        'Age': [18, 19, 20, 21, 22]\n",
    "    }, index=[1, 2, 3, 4, 5], columns=['Name', 'Age'])\n",
    "df"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:12:33.784502400Z",
     "start_time": "2025-08-26T06:12:33.769745800Z"
    }
   },
   "id": "d7eafac1c9fb448e"
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "行索引： Index([1, 2, 3, 4, 5], dtype='int64')\n",
      "列标签： Index(['Name', 'Age'], dtype='object')\n",
      "值： [['wdp' 18]\n",
      " ['wdm' 19]\n",
      " ['wdy' 20]\n",
      " ['wdf' 21]\n",
      " ['wdq' 22]]\n"
     ]
    }
   ],
   "source": [
    "# 行索引 、列标签、值\n",
    "print('行索引：', df.index)\n",
    "print('列标签：', df.columns)\n",
    "print('值：', df.values)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:17:20.674332600Z",
     "start_time": "2025-08-26T06:17:20.663787800Z"
    }
   },
   "id": "8c89c60a4af7caa0"
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "维度： 2\n"
     ]
    }
   ],
   "source": [
    "# 维度\n",
    "print('维度：', df.ndim)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:17:30.657695400Z",
     "start_time": "2025-08-26T06:17:30.647822700Z"
    }
   },
   "id": "db813a6bdf477eed"
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据类型： Name    object\n",
      "Age      int64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "#数据类型\n",
    "print('数据类型：', df.dtypes)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:17:41.063595800Z",
     "start_time": "2025-08-26T06:17:41.056426200Z"
    }
   },
   "id": "5b259cba5b6949cf"
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "形状： (5, 2)\n"
     ]
    }
   ],
   "source": [
    "# 形状\n",
    "print('形状：', df.shape)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:18:20.234857900Z",
     "start_time": "2025-08-26T06:18:20.192215100Z"
    }
   },
   "id": "c60719697abe28c2"
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "size： 10\n"
     ]
    }
   ],
   "source": [
    "#size\n",
    "print('size：', df.size)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:18:43.195584500Z",
     "start_time": "2025-08-26T06:18:43.182553100Z"
    }
   },
   "id": "316c9aaf9f1b4389"
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "行转列：         1    2    3    4    5\n",
      "Name  wdp  wdm  wdy  wdf  wdq\n",
      "Age    18   19   20   21   22\n"
     ]
    }
   ],
   "source": [
    "# 行列转置\n",
    "print('行转列：', df.T)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:18:56.888650500Z",
     "start_time": "2025-08-26T06:18:56.880302Z"
    }
   },
   "id": "25c04aa9f0ba9d43"
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取某行： Name    wdp\n",
      "Age      18\n",
      "Name: 1, dtype: object\n",
      "获取某行： Name    wdp\n",
      "Age      18\n",
      "Name: 1, dtype: object\n"
     ]
    }
   ],
   "source": [
    "#获取某行\n",
    "print('获取某行：', df.loc[1])\n",
    "# 同上面，隐式索引就是位置索引\n",
    "print('获取某行：', df.iloc[0])\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:21:34.216576600Z",
     "start_time": "2025-08-26T06:21:34.192859800Z"
    }
   },
   "id": "7cc7e2fcc37aee34"
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取某列： 1    wdp\n",
      "2    wdm\n",
      "3    wdy\n",
      "4    wdf\n",
      "5    wdq\n",
      "Name: Name, dtype: object\n",
      "获取某列： 1    wdp\n",
      "2    wdm\n",
      "3    wdy\n",
      "4    wdf\n",
      "5    wdq\n",
      "Name: Name, dtype: object\n",
      "获取某列： 1    wdp\n",
      "2    wdm\n",
      "3    wdy\n",
      "Name: Name, dtype: object\n",
      "获取某列： 2    wdm\n",
      "3    wdy\n",
      "Name: Name, dtype: object\n",
      "--获取某列： 1    wdp\n",
      "2    wdm\n",
      "3    wdy\n",
      "4    wdf\n",
      "5    wdq\n",
      "Name: Name, dtype: object\n",
      "--获取某列： 1    wdp\n",
      "2    wdm\n",
      "3    wdy\n",
      "4    wdf\n",
      "5    wdq\n",
      "Name: Name, dtype: object\n",
      "--获取某列：   Name\n",
      "1  wdp\n",
      "2  wdm\n",
      "3  wdy\n",
      "4  wdf\n",
      "5  wdq\n",
      "--获取某列：   Name  Age\n",
      "1  wdp   18\n",
      "2  wdm   19\n",
      "3  wdy   20\n",
      "4  wdf   21\n",
      "5  wdq   22\n"
     ]
    }
   ],
   "source": [
    "# 获取某列\n",
    "print('获取某列：', df.loc[:, 'Name'])\n",
    "print('获取某列：', df.iloc[:, 0])\n",
    "\n",
    "print('获取某列：', df.loc[1:3, 'Name'])\n",
    "print('获取某列：', df.iloc[1:3, 0])\n",
    "# 获取某列\n",
    "print('--获取某列：', df['Name'])\n",
    "print('--获取某列：', df.Name)\n",
    "# 获取多列数据\n",
    "print('--获取某列：', df[['Name']])\n",
    "print('--获取某列：', df[['Name', 'Age']])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:29:49.243020500Z",
     "start_time": "2025-08-26T06:29:49.231023300Z"
    }
   },
   "id": "d36ee09f30c26709"
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取单个元素： wdp\n",
      "获取单个元素： wdp\n",
      "获取单个元素： wdp\n",
      "获取单个元素： wdp\n"
     ]
    }
   ],
   "source": [
    "# 获取单个元素\n",
    "print('获取单个元素：', df.loc[1, 'Name'])\n",
    "print('获取单个元素：', df.iloc[0, 0])\n",
    "print('获取单个元素：', df.at[1, 'Name'])\n",
    "print('获取单个元素：', df.iat[0, 0])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:23:55.121607Z",
     "start_time": "2025-08-26T06:23:55.094749200Z"
    }
   },
   "id": "833dcd954e357455"
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "获取前几个数据：   Name  Age\n",
      "1  wdp   18\n",
      "2  wdm   19\n",
      "获取后几个数据：   Name  Age\n",
      "4  wdf   21\n",
      "5  wdq   22\n"
     ]
    }
   ],
   "source": [
    "# 获取前几行数据\n",
    "print('获取前几个数据：', df.head(2))\n",
    "# 获取后几行数据\n",
    "print('获取后几个数据：', df.tail(2))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:30:39.699563200Z",
     "start_time": "2025-08-26T06:30:39.669775700Z"
    }
   },
   "id": "9f2b5f1fe663f97e"
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "筛选：   Name  Age\n",
      "4  wdf   21\n",
      "5  wdq   22\n",
      "筛选：   Name  Age\n",
      "4  wdf   21\n"
     ]
    }
   ],
   "source": [
    "# 筛选\n",
    "print('筛选：', df[df['Age'] > 20])\n",
    "# print('筛选：', df[df.Age > 20])\n",
    "# print('筛选：', df[(df['Age'] > 20) & (df['Name'] == 'wdf')])\n",
    "print('筛选：', df[(df.Age > 20) & (df.Name == 'wdf')])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:33:30.821785800Z",
     "start_time": "2025-08-26T06:33:30.805125Z"
    }
   },
   "id": "4083bf830473847d"
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "是否包含： True\n",
      "是否包含：     Name    Age\n",
      "1  False  False\n",
      "2  False  False\n",
      "3  False  False\n",
      "4   True  False\n",
      "5  False   True\n"
     ]
    }
   ],
   "source": [
    "# 是否包含列\n",
    "print('是否包含：', 'Name' in df)\n",
    "\n",
    "# 是否包含某个元素\n",
    "print('是否包含：',df.isin(['wdf',22]))\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:39:41.817821300Z",
     "start_time": "2025-08-26T06:39:41.794219700Z"
    }
   },
   "id": "e9a530db696f0c03"
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "是否是缺失值：     Name    Age\n",
      "1  False  False\n",
      "2  False  False\n",
      "3  False  False\n",
      "4  False  False\n",
      "5  False  False\n"
     ]
    }
   ],
   "source": [
    "# 是否是缺失值\n",
    "print('是否是缺失值：', df.isnull())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:40:14.934640800Z",
     "start_time": "2025-08-26T06:40:14.918742600Z"
    }
   },
   "id": "ff6468f9e552f9bd"
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "求和： Name    wdpwdmwdywdfwdq\n",
      "Age                 100\n",
      "dtype: object\n",
      "age求和： 100\n",
      "age求最大值： 22\n",
      "age求最小值： 18\n",
      "age求平均值： 20.0\n"
     ]
    }
   ],
   "source": [
    "# 求和、最大值、最小值、平均值等\n",
    "print('求和：', df.sum())\n",
    "print('age求和：', df.Age.sum())\n",
    "print('age求最大值：', df.Age.max())\n",
    "print('age求最小值：', df.Age.min())\n",
    "print('age求平均值：', df.Age.mean())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:42:19.292483900Z",
     "start_time": "2025-08-26T06:42:19.258206900Z"
    }
   },
   "id": "b895cb636ecf9a70"
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "排序：   Name  Age\n",
      "5  wdq   22\n",
      "4  wdf   21\n",
      "3  wdy   20\n",
      "2  wdm   19\n",
      "1  wdp   18\n",
      "多列排序：   Name  Age\n",
      "1  wdp   18\n",
      "2  wdm   19\n",
      "3  wdy   20\n",
      "4  wdf   21\n",
      "5  wdq   22\n"
     ]
    }
   ],
   "source": [
    "# 排序\n",
    "print('排序：', df.sort_values(by='Age',ascending= False))\n",
    "# 多列排序\n",
    "print('多列排序：', df.sort_values(by=['Age', 'Name'], ascending=[True, True]))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2025-08-26T06:50:15.840589700Z",
     "start_time": "2025-08-26T06:50:15.830249300Z"
    }
   },
   "id": "f845e49f97592f8f"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "fc2dba74442a04d9"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
